package com.example.demo.bean;



import org.springframework.http.HttpStatus;

import java.io.Serializable;

/**
 * com.thunisoft.dpfx.pojo.vo ResultVO
 *
 * @author Lyb
 * @version 1.0
 * @date 2019/9/4 15:18
 */
public class ResultVO implements Serializable {

    private static final long serialVersionUID = 6734545938995556594L;
    private Integer code;

    private Boolean success;

    private String message;

    private Object data;

    private String result;

    private String status;

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public String getResult() {
        return result;
    }

    public void setResult(String result) {
        this.result = result;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public Boolean getSuccess() {
        return success;
    }

    public void setSuccess(Boolean success) {
        this.success = success;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    /**
     * 默认成功
     * @param vo 数据
     * @return 封装的页面返回对象
     */
      public static ResultVO success(Object vo) {
        ResultVO resultVO = new ResultVO();
        resultVO.setCode(HttpStatus.OK.value());
        resultVO.setSuccess(true);
        resultVO.setMessage("请求成功");
        resultVO.setData(vo);
        return resultVO;
    }




    /**
     * 插入修改更新成功
     * @param insertNums
     * @param removeNums
     * @param updateNums
     * @return
     * @author kongjiawei
     * @date 2021/9/5 22:52
     */
    public static ResultVO success(int insertNums,int removeNums,int updateNums){
        ResultVO resultVO = new ResultVO();
        resultVO.setCode(0);
        resultVO.setMessage("请求成功");
        resultVO.setStatus("200");
        resultVO.setSuccess(true);
        resultVO.setResult("insertRows:" + insertNums + ",removeRows:" + removeNums + ",updateRows:" + updateNums);
        return resultVO;
    }

    public static ResultVO error(StringBuffer message,int num){
        ResultVO resultVO = new ResultVO();
        resultVO.setCode(0);
        resultVO.setMessage("请求成功");
        resultVO.setStatus("200");
        resultVO.setSuccess(true);
        resultVO.setResult(message+"  remove"+num);
        return resultVO;
    }


    /**
     * 默认失败
     * @param msg 失败消息
     * @return 封装的页面返回对象
     */
    public static ResultVO error(String msg) {
        ResultVO resultVO = new ResultVO();
        resultVO.setCode(HttpStatus.INTERNAL_SERVER_ERROR.value());
        resultVO.setSuccess(false);
        resultVO.setMessage(msg);
        return resultVO;
    }

    @Override
    public String toString() {
        return "ResultVO{" +
                "code=" + code +
                ", success=" + success +
                ", message='" + message + '\'' +
                ", data=" + data +
                '}';
    }
}
